package k8s

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/api/core/v1"
)

type K8sPersistentVolumeClaim struct {
	Name string												`json:"name"`
	Namespace string
	Status v1.PersistentVolumeClaimPhase
	PersistentVolume string									`json:"persistentVolume"`
	AccessModes []v1.PersistentVolumeAccessMode
	RequestTotal v1.ResourceList
	Labels map[string]string								`json:"labels"`
	Createdate string										`json:"createdate"`
}


func getPersistentVolumeClaim(name string)(k8sPvcs []K8sPersistentVolumeClaim, err error)  {
	pvcs,_ := clientset.CoreV1().PersistentVolumeClaims(name).List(metav1.ListOptions{})
	for _,pvc := range pvcs.Items {

		p := K8sPersistentVolumeClaim{
			Name: pvc.Name,
			Labels: pvc.Labels,
			PersistentVolume: pvc.Spec.VolumeName,
			Createdate: pvc.CreationTimestamp.Format("2006-01-02"),
		}
		k8sPvcs = append(k8sPvcs,p)
	}
	return
}


func GetKubernetesPersistentVolumeClaim(ns string,name string)(k8sPvc K8sPersistentVolumeClaim,err error)  {
	pvc,_ := clientset.CoreV1().PersistentVolumeClaims(ns).Get(name,metav1.GetOptions{})
	k8sPvc = K8sPersistentVolumeClaim{
		Name: pvc.Name,
		Namespace: pvc.Namespace,
		Createdate: pvc.CreationTimestamp.Format("2006-01-02"),
		Status: pvc.Status.Phase,
		PersistentVolume: pvc.Spec.VolumeName,
		RequestTotal: pvc.Spec.Resources.Requests,
		AccessModes: pvc.Spec.AccessModes,
	}
	return


}
